package com.leyou.controller;

import com.leyou.Interface.EnableExceptionAdvice;
import com.leyou.pojo.Item;
import com.leyou.service.ItemService;
import com.netflix.ribbon.proxy.annotation.Http;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author jshstart
 * @creat 2020-12-08 20:52
 */
@RestController
@RequestMapping("/item")

public class ItemController {
    @Autowired
    private ItemService itemService;
    @PostMapping()
    public ResponseEntity<Item> saveItem(Item item){
            Item item1= itemService.saveItem(item);
            return ResponseEntity.status(HttpStatus.CREATED).body(item1);

//        手动抛出异常，service的异常一定要抛出，才能让数据库进行回滚
//        try {
//            Item item1= itemService.saveItem(item);
//            return ResponseEntity.status(HttpStatus.CREATED).body(item1);
//        } catch (Exception e) {
//            return ResponseEntity.status(400).body(null);
//        }
    }
}
